package net.entelijan.cobean.bind.impl;

import net.entelijan.cobean.bind.IBeanProperty;

class SpringBeanProperty implements IBeanProperty {

    private IBeanProperty beanPropertyVariant;

    public SpringBeanProperty(Object bean, String property) {
        super();
        if (property != null) {
            if (property.contains(".")) {
                throw new IllegalStateException("No nested properties like '" + property
                        + "' are allowed");
            }
            this.beanPropertyVariant = new PropertyBeanPropertyVariante(bean, property);
        } else {
            this.beanPropertyVariant = new PlainBeanPropertyVariante(bean);

        }
    }

    public Object getValue() {
        return this.beanPropertyVariant.getValue();
    }

    public void setValue(Object obj) {
        this.beanPropertyVariant.setValue(obj);
    }

    public Object createPlaceholder() {
        return this.beanPropertyVariant.createPlaceholder();
    }

    @Override
    public String toString() {
        return "" + this.beanPropertyVariant;
    }

    @Override
    public String getPropertyName() {
        return this.beanPropertyVariant.getPropertyName();
    }

    @Override
    public boolean isCollection() {
        return this.beanPropertyVariant.isCollection();
    }

    @Override
    public Object getBean() {
        return this.beanPropertyVariant.getBean();
    }

}
